//
// Created by jyh on 2021/8/5.
//

#ifndef BBOVRSCHIP_RNXEPH_H
#define BBOVRSCHIP_RNXEPH_H

#define MAXGNSSSAT 120
#define MAXGLSSAT 40

#include "Const.h"

// TYPEDEF
typedef struct GPSEPH {
    double dt;
    char cprn[LEN_PRN];
    int mjd;
    double sod;
    double a0, a1, a2;
    unsigned int aode;
    double crs, dn;
    double m0, cuc, e;
    double cus, roota;
    double toe, cic, omega0;
    double cis, i0, crc;
    double omega, omegadot;
    double idot, resvd0, week, resvd1;
    double accu, hlth, tgd, tgd1, aodc;
    double iodc, signal_idx, delta_A, A_DOT, delta_n_dot;
    time_t gent;
};
typedef struct GLSEPH {
    double dt;
    char cprn[LEN_PRN];
    int mjd, aode;
    double sod;
    double tau;
    double gamma;
    double tk;
    double pos[3];
    double vel[3];
    double acc[3];
    double health;
    double frenum;
    double age;
    time_t gent;
};
typedef struct Rnxeph {
        // ionospheric correction parameters
        char ionc[MAXSYS][2][LEN_EPHION];
        double ion[MAXSYS][2][4];
        /// inner structure
        char curFile[1024];
        int mjd, mjd0, mjd1, intver;
        double sod, sod0, sod1;
        // header part
        double ver;
        // corrections to transform the system to UTC or other time systems
        char timc[MAXSYS][2][LEN_EPHION];
        double tim[MAXSYS][2][4];
        // number of leap second since 6-Jan-980
        int leap;
        int size_gnssEph;
        int size_glsEph;

        struct GPSEPH gnsseph[MAXGNSSSAT];
        struct GLSEPH glseph[MAXGLSSAT];
        FILE* in;

        bool isOpen;
};

// FUNCTION
void Rnxeph_GPSEPH_initial(struct GPSEPH *eph);
void Rnxeph_GLSEPH_initial(struct GLSEPH *ephr);
void Rnxeph_initial();
int map_gpseph_find(struct GPSEPH *gnsseph, char keyprn[LEN_PRN]);
int map_glseph_find(struct GLSEPH *glseph, char keyprn[LEN_PRN]);


// VARIABALE
extern struct Rnxeph BRDEPH;

#endif //BBOVRSCHIP_RNXEPH_H
